package ace.tool.generate.code.impl.resolver.scheme.resolver.core;

import ace.tool.generate.code.impl.resolver.scheme.model.bo.core.test.TestResourceApplicationYmlFileInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.ProjectInfo;
import java.util.HashMap;
import java.util.Map;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import org.apache.commons.text.StringSubstitutor;

/**
 * @author caspar
 * @date 2023/11/17 10:34
 */
@Builder
@RequiredArgsConstructor
public class TestResourceApplicationYmlFileInfoResolver {
  private final ProjectInfo coreProjectInfo;

  public TestResourceApplicationYmlFileInfo resolve() {

    return TestResourceApplicationYmlFileInfo.builder()
        .fileName(this.getFileName())
        .fileFullName(this.getFileFullName())
        .build();
  }

  private String getFileName() {
    return String.format("application.yml");
  }

  private String getFileFullName() {
    Map<String, String> data = new HashMap<>();
    data.put("rootDir", coreProjectInfo.getTestResourcesRootDir());
    data.put("fileName", this.getFileName());
    return StringSubstitutor.replace("${rootDir}/${fileName}", data);
  }
}
